<?php
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

/**
* @package Joomla
* @subpackage Weblinks
*/
class HTML_orderonline {
	function showCart( &$rows ){
	global $database;
	?>
	<div class="showContent">
		<div class="titleContent"><?php echo _YOUR_CART;?></div>
		<div class="lsNews">
			<form name="frmCart" action="index.php?option=com_orderonline&task=update" method="post">
			<table border="0" cellpadding="0" cellspacing="5" width="100%">
				<tr height="25">
					<td bgcolor="#ccc"><b><?php echo _CART_STT;?></b></td>
					<td bgcolor="#ccc"><b><?php echo _CART_SP;?></b></td>
					<td bgcolor="#ccc"><b><?php echo _CART_SO_LUONG;?></b></td>
					<td bgcolor="#ccc" class="end"><b><?php echo _CART_THANH_TIEN;?></b></td>
				</tr>
				<?php
				$sum = 0;
				for ($i=0; $i<count($rows); $i++){
				$price = $rows[$i]->price*$rows[$i]->so_luong;
				$sum = $sum + $price;
				?>
				<tr>
					<td><?php echo $i+1;?></td>
					<td><?php echo $rows[$i]->title;?></td>
					<td><input type="text" name="so_luong_<?php echo $rows[$i]->id;?>" value="<?php echo $rows[$i]->so_luong;?>" size="10" /></td>
					<td class="end"><span style="color:red;"><?php echo number_format($price,0,',','.');?></span> <?php echo _TIEN_TE;?></td>
					<input type="hidden" value="<?php echo $rows[$i]->id;?>" name="product_id_<?php echo $rows[$i]->id;?>" />
				</tr>
				<tr height="1"><td colspan="4" bgcolor="#ccc"></td></tr>
				<?php
				}
				?>
				<tr>
					<td colspan="2" style="border-right:0;">
					<input type="submit" class="submit" name="updateCart" value="<?php echo _CART_BT_CAP_NHAT;?>" style="margin-right:10px;" />
					<a href="index.php"><input type="button" class="submit" name="continueCart" value="<?php echo _CART_BT_TIEP_TUC;?>" style="margin-right:10px;" /></a>
					<a href="index.php?option=com_orderonline&task=payment"><input type="button" class="submit" name="paymentCart" value="<?php echo _CART_BT_THANH_TOAN;?>" /></a>
					</td>
					<td colspan="2" style="text-align:right; padding-right:10px; border-right:0;">
					<b><?php echo _CART_TONG_TIEN;?></b>: <span style="color:red;"><?php echo number_format($sum,0,',','.');?></span> <?php echo _TIEN_TE;?>
					</td>
				</tr>
			</table>
			</form>
		</div>	
	</div>
	<?php
	}
	
	function paymentCart( &$rows ){
	?>
	<script type="text/javascript">
	var form = document.frmPayment;
	function check(form){
		if (form.fullname.value==''){
			alert('<?php echo _CT_MS_FULLNAME;?>');
			form.fullname.focus();
			return false;
		}
		else if (form.address.value==''){
			alert('<?php echo _CART_MS_DIA_CHI;?>');
			form.address.focus();
			return false;
		}
		else if (form.phone.value==''){
			alert('<?php echo _CART_MS_DIEN_THOAI;?>');
			form.phone.focus();
			return false;
		}
		else if (form.email.value==''){
			alert('<?php echo _CT_MS_EMAIL;?>');
			form.email.focus();
			return false;
		}
		else if (form.email.value.indexOf('@',0) == -1 || form.email.value.indexOf('.',0) == -1){
			alert("<?php echo _CT_MS_EMAIL_INVALID;?>") ;
			form.email.select() ;
			return false ;
		}
		return true;
	}
	</script>
	<div class="showContent">
		<div class="titleContent"><?php echo _YOUR_CART;?></div>
		<div class="lsNews">
			<table border="0" cellpadding="0" cellspacing="5" width="100%">
				<tr height="25">
					<td bgcolor="#ccc"><b><?php echo _CART_STT;?></b></td>
					<td bgcolor="#ccc"><b><?php echo _CART_SP;?></b></td>
					<td bgcolor="#ccc"><b><?php echo _CART_SO_LUONG;?></b></td>
					<td bgcolor="#ccc" class="end"><b><?php echo _CART_THANH_TIEN;?></b></td>
				</tr>
				<?php
				$sum = 0;
				for ($i=0; $i<count($rows); $i++){
				$price = $rows[$i]->price*$rows[$i]->so_luong;
				$sum = $sum + $price;
				?>
				<tr>
					<td><?php echo $i+1;?></td>
					<td><?php echo $rows[$i]->title;?></td>
					<td><input type="text" name="so_luong_<?php echo $rows[$i]->id;?>" value="<?php echo $rows[$i]->so_luong;?>" size="10" /></td>
					<td class="end"><span style="color:red;"><?php echo number_format($price,0,',','.');?></span> <?php echo _TIEN_TE;?></td>
				</tr>
				<tr height="1"><td colspan="4" bgcolor="#ccc"></td></tr>
				<?php
				}
				?>
				<tr>
					<td colspan="2" style="border-right:0;">
					<a href="index.php"><input type="button" class="submit" name="continueCart" value="Tiếp tục mua" style="margin-right:10px;" /></a>
					</td>
					<td colspan="2" style="text-align:right; padding-right:10px; border-right:0;">
					<b><?php echo _CART_TONG_TIEN;?></b>: <span style="color:red;"><?php echo number_format($sum,0,',','.');?></span> <?php echo _TIEN_TE;?>
					</td>
				</tr>
			</table>
			<form name="frmPayment" action="" method="post" onsubmit="javascript:return check(this);">
			<table border="0" cellpadding="0" cellspacing="10" width="100%">
				<tr>
					<td colspan="2"><b><?php echo _CT_REQUIRE;?></b> <b style="color:red;">(*)</b></td>
				</tr>
				<tr>
					<td width="30%"><?php echo _CT_NAME;?> :</td>
					<td width="65%"><input type="text" name="fullname" value="" size="45" /> <b style="color:red;">(*)</b></td>
				</tr>
				<tr>
					<td><?php echo _CT_ADDRESS;?> :</td>
					<td><input type="text" name="address" value="" size="45" /> <b style="color:red;">(*)</b></td>
				</tr>
				<tr>
					<td><?php echo _CT_PHONE;?> :</td>
					<td><input type="text" name="phone" value="" size="45" /> <b style="color:red;">(*)</b></td>
				</tr>
				<tr>
					<td><?php echo _CT_EMAIL;?> :</td>
					<td><input type="text" name="email" value="" size="45" /> <b style="color:red;">(*)</b></td>
				</tr>
				<tr>
					<td style="vertical-align:top; padding-top:10px;"><?php echo _CT_CONTENT_MAIL;?> :</td>
					<td><textarea name="content" cols="50" rows="5"></textarea></td>
				</tr>
				<tr>
					<td></td>
					<td><input type="submit" class="submit" name="submit" value="<?php echo _CART_BT_CHAP_NHAN;?>" /></td>
				</tr>
			</table>
			<input type="hidden" name="hid" value="1" />
			</form>
		</div>	
	</div>
	<?php
	}
	
	function message($msg){
	?>
	<div class="showContent">
		<div class="titleContent"><?php echo _CART_THONG_BAO_MS;?></div>
		<p style="color:red; line-height:35px; text-align:center;"><?php echo $msg;?></p>
	</div>	
	<?php
	}
}
?>